<!DOCTYPE html>

<?php
  include '../../dbconnect.php';
?>

<!--[if lt IE 9]><html class="ie"><![endif]-->
<!--[if gte IE 9]><!--><html><!--<![endif]-->

<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=940px, minimum-scale=0, initial-scale=0"/>

<title>Sermons - Candlestick Baptist Church</title>

<link rel="shortcut icon" href="../favicon.ico?v=2"/>
<link rel="stylesheet" href="../Content/Styles/site.css"/>
<link rel="stylesheet" href="../Content/Styles/colors.css"/>
<link rel="stylesheet" href="../Content/Styles/tablepagination.css"/>
<link rel="stylesheet" href="../Content/MediaElementSkin/mediaelementplayer.css" />
<link rel="stylesheet" href="../Content/Styles/audio.css"/>

<!--[if lt IE 9]>
<script type="text/javascript" src="Content/Javascript/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="../Content/Javascript/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../Content/Javascript/site.js"></script>
<script type="text/javascript" src="../Content/Javascript/Tables/jquery.tablePagination.0.5.js"></script>
<script type="text/javascript" src="../Content/Javascript/Tables/sermonTable1.js"></script>
<script type="text/javascript" src="../Content/Javascript/mediaelement-and-player.min.js"></script>
<script type="text/javascript" src="../Content/Javascript/audioPlayer.js"></script>
</head>

<body lang="en" class="colorBackground">
    <div id="headerWrapper" class="colorPrimary-5">
        <div id="header">
            <img alt="" src="../Content/Images/title.png" />
        </div>
    </div>
    <div id="menuWrapper" class="colorPrimary-2">
        <div id="menu">
            <ul id="cssdropdown">
<?php
  $menuHeadLinkData = mysql_query("SELECT * FROM `MenuHeadLink` WHERE `Active` = 1 ORDER BY `Order`");
  $menuHeadLinkDataNumRows = mysql_numrows($menuHeadLinkData);
  echo "                ";
  for ($i = 0; $i < $menuHeadLinkDataNumRows; $i++) {
    $headLinkID = mysql_result($menuHeadLinkData, $i, 'ID');
	$headLinkAbsolutePath = mysql_result($menuHeadLinkData, $i, 'AbsolutePath');
    $headLinkHRef = mysql_result($menuHeadLinkData, $i, 'HRef');
    $headLinkText = mysql_result($menuHeadLinkData, $i, 'Text');
	$headLinkNewWindow = mysql_result($menuHeadLinkData, $i, 'NewWindow');
    $menuSubLinkData = mysql_query("SELECT * FROM `MenuSubLink` WHERE `MenuHeadLinkID` = $headLinkID AND `Active` = 1 ORDER BY `Order`");
    $menuSubLinkDataNumRows = mysql_numrows($menuSubLinkData);
    echo "<li class=\"headlink\">\n",
         "                    <a href=\"";
	if ($headLinkAbsolutePath == 0) {
	  echo "../";
	}
	echo "$headLinkHRef\"";
	if ($headLinkNewWindow == 1) {
	  echo " target=\"_blank\"";
	}
	echo ">$headLinkText</a>\n";
    if ($menuSubLinkDataNumRows > 0) {
      echo "                    <ul class=\"colorSecondary-a-1\">\n";
      for ($j = 0; $j < $menuSubLinkDataNumRows; $j++) {
	    $subLinkAbsolutePath = mysql_result($menuSubLinkData, $j, 'AbsolutePath');
        $subLinkHRef = mysql_result($menuSubLinkData, $j, 'HRef');
        $subLinkText = mysql_result($menuSubLinkData, $j, 'Text');
		$subLinkNewWindow = mysql_result($menuSubLinkData, $j, 'NewWindow');
        echo "                        <li><a href=\"";
        if ($subLinkAbsolutePath == 0) {
	      echo "../";
	    }
	    echo "$subLinkHRef\"";
	    if ($subLinkNewWindow == 1) {
	      echo " target=\"_blank\"";
	    }
	    echo ">$subLinkText</a></li>\n";
      }
      echo "                    </ul>\n";
    }
    echo "                </li>";
  }
  echo "\n";
?>
            </ul>
        </div>
    </div>
    <div id="pageWrapper" class="colorWhite colorBorder">
        <div class="pageTitle">
            <h1 class="center">Sermons</h1>
        </div>
        <div class="column-1">
            <table id="sermonTable" class="colorComplement-5" border="1" cellpadding="8">
<?php
  $sermonData = mysql_query(
    "SELECT A.*, S.Code AS `Service`
     FROM `Audio` A
       INNER JOIN `Service` S ON A.`ServiceID` = S.ID
     WHERE A.`Active` = 1
       AND A.`Type` = 'Sermon'
       AND S.`Active` = 1
     ORDER BY A.`Date`, S.`Order`, A.`Order`"
  );
  $sermonDataNumRows = mysql_numrows($sermonData);
  for ($i = 0; $i < $sermonDataNumRows; $i++) {
    $explodedDate = explode('-', mysql_result($sermonData, $i, 'Date'));
    $month = $explodedDate[1];
    $day = $explodedDate[2];
    $year = substr($explodedDate[0], -2);
    $date = implode('/', array($month, $day, $year));
    $service = mysql_result($sermonData, $i, 'Service');
    $preacher = mysql_result($sermonData, $i, 'Preacher');
    $title = mysql_result($sermonData, $i, 'Title');
    $filePath = mysql_result($sermonData, $i, 'FilePath');
?>
                    <tr>
                        <td width="10%">
<?php
    echo "                            $date\n";
?>
                        </td>
						<td width="13%">
<?php
    echo "                            $service\n";
?>
						</td>
                        <td width="21%">
<?php
    echo "                            $preacher\n";
?>
                        </td>
                        <td width="56%">
<?php
    echo "                            <input type=\"hidden\" id=\"player-item-$i\" value=\"../$filePath\" />\n",
         "                            <a id=\"player-link-$i\" class=\"colorSecondary-a-2\" onclick=\"playLink(this);\"\n",
         "                                href=\"java", "script:;\">$title</a>\n",
         "                            <a href=\"../php/download.php?file=../$filePath\"\n",
         "                                title=\"Download\"><img border=\"0\" src=\"../Content/Images/download.png\" alt=\"Download\" /></a>\n";
?>
                        </td>
                    </tr>
<?php
  }
?>
            </table>
<?php
  $firstAudioFile = mysql_result($sermonData, 0, 'FilePath');
  if (!is_null($firstAudioFile)) {
    echo "            <audio id=\"player\" src=\"../$firstAudioFile\" type=\"audio/mp3\" controls=\"controls\"></audio>\n";
  }
?>
        </div>
    </div>
    <div id="footerWrapper" class="colorPrimary-5">
        <div id="footer">
            <span>2631 Spring Cypress Road Spring, TX 77388</span>
            <a href="../AboutUs/whoweare.html#contactUs">Contact Us</a>
        </div>
    </div>
</body>
</html>
<?php
  mysql_close();
?>